const mongoose = require("mongoose");
const schedulesModel = mongoose.model("schedules");

module.exports = {
    add: async (schedule) => {
        const data = await schedulesModel.create(schedule);
        return data;
    },
    get: async ({ page, limit }) => {
        limit = ~~limit;
        const result = {};
        result.total = await schedulesModel.countDocuments();
        result.rows = await schedulesModel.find().populate(["movieId", "cinemasId", "theaterId"]).skip((page - 1) * limit).limit(limit).exec();
        return result;
    },
    updata: async (conditions, doc) => await schedulesModel.updateOne(conditions, doc),
    delete: async (_id) => await schedulesModel.deleteOne({ _id }),
    getOne: async _id => await schedulesModel.findOne({ _id }).populate(["movieId", "cinemasId", "theaterId"]),
    getAll : async () => await schedulesModel.find().populate(["movieId", "cinemasId", "theaterId"]),
}